package com.hujie.sqlqueryes.service.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * JSON转义工具类
 */
public class JsonEscapeUtil {
    
    private static final Logger logger = LoggerFactory.getLogger(JsonEscapeUtil.class);
    
    /**
     * 转义JSON字符串中的特殊字符
     * @param str 原始字符串
     * @return 转义后的字符串
     */
    public static String escapeJsonString(String str) {
        if (str == null) {
            return null;
        }
        return str.replace("\\", "\\\\")
                  .replace("\"", "\\\"")
                  .replace("\b", "\\b")
                  .replace("\f", "\\f")
                  .replace("\n", "\\n")
                  .replace("\r", "\\r")
                  .replace("\t", "\\t");
    }
}